/**!
 * Copyright(c) cnpmjs.org and other contributors.
 * MIT Licensed
 *
 * Authors:
 *  dead_horse <dead_horse@qq.com>
 *  fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
 */

'use strict';

/**
 * Module dependencies.
 */

const graceful = require('graceful');
const config = require('./server/config');
// const winston = require('winston')

const web = require('./server/app');
const logger = require('./server/lib/logger').crash;

let port = config.app.port;
web.listen(port);

// logger.error('a test err')
console.log('\n*****ENV:%s*******', config.app.env);
console.log('[%s][worker:%d] Server started, %s server listen at %s:%d',
  new Date(), process.pid, config.app.name,
  'localhost', port);
console.log('********************\n');

graceful({
  server: [web],
  error: function (err, throwErrorCount) {
    if (err.message) {
      err.message += ' (uncaughtException throw ' + throwErrorCount + ' times on pid:' + process.pid + ')';
    }
    console.error(err);
    console.error(err.stack);
    logger.error(err);
  }
});
